<HTML>
<HEAD>
<!-- @(#) $Revision: 4.8 $ $Source: /cvsroot/judy/doc/ext/Judy1_funcs_3.htm,v $ --->
<TITLE>Judy1_funcs(3)</TITLE>
</HEAD>
<BODY>
<TABLE border=0 width="100%"><TR>
<TD width="40%" align="left">Judy1_funcs(3)</TD>
<TD width="10%" align="center">     </TD>
<TD width="40%" align="right">Judy1_funcs(3)</TD>
</TR></TABLE>
<P>
<DL>
<!----------------->
<DT><B>NAME</B></DT>
<DD>
Judy1 functions -
C library for creating and accessing a dynamic array of bits, using
any value of a word as an index
<!----------------->
<P>
<DT><B>SYNOPSIS</B></DT>
<DD>
<B><PRE>
int    <A href="#Judy1Set"       >Judy1Set</A>(       PPvoid_t PPJ1Array, Word_t   Index,  PJError_t PJError);
int    <A href="#Judy1Unset"     >Judy1Unset</A>(     PPvoid_t PPJ1Array, Word_t   Index,  PJError_t PJError);
int    <A href="#Judy1Test"      >Judy1Test</A>(      Pcvoid_t  PJ1Array, Word_t   Index,  PJError_t PJError);
Word_t <A href="#Judy1Count"     >Judy1Count</A>(     Pcvoid_t  PJ1Array, Word_t   Index1, Word_t    Index2, PJError_t PJError);
int    <A href="#Judy1ByCount"   >Judy1ByCount</A>(   Pcvoid_t  PJ1Array, Word_t   Nth,    Word_t * PIndex,  PJError_t PJError);
Word_t <A href="#Judy1FreeArray" >Judy1FreeArray</A>( PPvoid_t PPJ1Array, PJError_t PJError);
Word_t <A href="#Judy1MemUsed"   >Judy1MemUsed</A>(   Pcvoid_t  PJ1Array);
int    <A href="#Judy1First"     >Judy1First</A>(     Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1Next"      >Judy1Next</A>(      Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1Last"      >Judy1Last</A>(      Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1Prev"      >Judy1Prev</A>(      Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1FirstEmpty">Judy1FirstEmpty</A>(Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1NextEmpty" >Judy1NextEmpty</A>( Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1LastEmpty" >Judy1LastEmpty</A>( Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
int    <A href="#Judy1PrevEmpty" >Judy1PrevEmpty</A>( Pcvoid_t  PJ1Array, Word_t * PIndex, PJError_t PJError);
</PRE></B>
<!----------------->
<P>
<DT><B>DESCRIPTION</B></DT>
<DD>
A macro equivalent exists for each function call.
Because the macro forms are sometimes faster and have a simpler error
handling interface than the equivalent functions,
they are the preferred way of calling the Judy1 functions.
See <A href="Judy1_3.htm">Judy1(3)</A>
for more information.
The function call definitions are included here for completeness.
<P>
One of the difficulties in using the Judy1 function calls lies in
determining whether to pass a pointer or the address of a pointer.
Since the functions that modify the Judy1 array must also modify the
pointer to the Judy1 array, you must pass the address of the pointer
rather than the pointer itself.
This often leads to hard-to-debug programmatic errors.
In practice, the macros allow the compiler to catch programming
errors when pointers instead of addresses of pointers are passed.
<P>
The Judy1 function calls have an additional parameter beyond
those specified in the macro calls.  This parameter is either a
pointer to an error structure, or <B>NULL</B> (in which case the
detailed error information is not returned).
<P>
In the following descriptions, the functions are described in
terms of how the macros use them (only in the case of
<B>#define JUDYERROR_NOTEST 1</B>).  This is the suggested use
of the macros after your program has been fully debugged.
When the <B>JUDYERROR_NOTEST</B> macro is not specified,
an error structure is declared to store error information
returned from the Judy1 functions when an error occurs.
<P>
Notice the placement of the <B>&amp;</B> in the different functions.
<P>
<DL>
<DT><A name="Judy1Set"><B>Judy1Set(&amp;PJ1Array, Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1S(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1Set(&amp;PJ1Array, Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1Unset"><B>Judy1Unset(&amp;PJ1Array, Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1U(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1Unset(&amp;PJ1Array, Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1Test"><B>Judy1Test(PJ1Array, Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1T(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1Test(PJ1Array, Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1Count"><B>Judy1Count(PJ1Array, Index1, Index2, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1C(Rc_word, PJ1Array, Index1, Index2) \
   Rc_word = Judy1Count(PJ1Array, Index1, Index2, PJE0)

</PRE>
A return value of 0 can be an error, valid as a count, or it can indicate a special case
for a fully-populated array (32-bit machines only).  If necessary, the following
code can be used to disambiguate this return:
<PRE>
JError_t JError;

Rc_word = Judy1Count(PJ1Array, Index1, Index2, &amp;JError);
if (Rc_word == 0)
{
    if (JU_ERRNO(&amp;JError) == JU_ERRNO_NONE)
        printf("Judy1 array population == 0\n");
    if (JU_ERRNO(&amp;JError) == JU_ERRNO_FULL)
        printf("Judy1 array population == 2^32\n");
    if (JU_ERRNO(&amp;JError) == JU_ERRNO_NULLPPARRAY)
        goto NullArray;
    if (JU_ERRNO(&amp;JError) >  JU_ERRNO_NFMAX)
        goto Null_or_CorruptArray;
}
</PRE>
<P>
<DT><A name="Judy1ByCount"><B>Judy1ByCount(PJ1Array, Nth, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1BC(Rc_int, PJ1Array, Nth, Index) \
   Rc_int = Judy1ByCount(PJ1Array, Nth, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1FreeArray"><B>Judy1FreeArray(&amp;PJ1Array, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1FA(Rc_word, PJ1Array) \
   Rc_word = Judy1FreeArray(&amp;PJ1Array, PJE0)

</PRE>
<P>
<DT><A name="Judy1MemUsed"><B>Judy1MemUsed(PJ1Array)</B></A></DT>
<DD>
<PRE>
#define J1MU(Rc_word, PJ1Array) \
   Rc_word = Judy1MemUsed(PJ1Array)

</PRE>
<P>
<DT><A name="Judy1First"><B>Judy1First(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1F(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1First(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1Next"><B>Judy1Next(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1N(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1Next(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1Last"><B>Judy1Last(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1L(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1Last(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1Prev"><B>Judy1Prev(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1P(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1Prev(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1FirstEmpty"><B>Judy1FirstEmpty(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1FE(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1FirstEmpty(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1NextEmpty"><B>Judy1NextEmpty(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1NE(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1NextEmpty(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1LastEmpty"><B>Judy1LastEmpty(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1LE(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1LastEmpty(PJ1Array, &amp;Index, PJE0)

</PRE>
<P>
<DT><A name="Judy1PrevEmpty"><B>Judy1PrevEmpty(PJ1Array, &amp;Index, &amp;JError)</B></A></DT>
<DD>
<PRE>
#define J1PE(Rc_int, PJ1Array, Index) \
   Rc_int = Judy1PrevEmpty(PJ1Array, &amp;Index, PJE0)

</PRE>
</DL>
<P>
Definitions for all of the Judy functions, the types
<B>Pvoid_t</B>,
<B>Pcvoid_t</B>,
<B>PPvoid_t</B>,
<B>Word_t</B>,
<B>JError_t</B>,
and
<B>PJError_t</B>,
the constants
<B>NULL</B>,
<B>JU_ERRNO_*</B>,
<B>JERR</B>,
and
<B>PJE0</B>,
are provided in the <B>Judy.h</B> header file
(/usr/include/Judy.h).
<B>Note</B>:  Callers should define Judy1 arrays as type <B>Pvoid_t</B>,
which can be passed by value to functions that take
<B>Pcvoid_t</B> (constant <B>Pvoid_t</B>),
and also by address to functions that take <B>PPvoid_t</B>.
<!----------------->
<P>
<DT><B>AUTHOR</B></DT>
<DD>
Judy was invented by Doug Baskins and implemented by Hewlett-Packard.
<!----------------->
<P>
<DT><B>SEE ALSO</B></DT>
<DD>
<A href="Judy_3.htm">Judy(3)</A>,
<A href="JudyL_3.htm">JudyL(3)</A>,
<A href="JudySL_3.htm">JudySL(3)</A>,
<A href="JudyHS_3.htm">JudyHS(3)</A>,
<BR>
<I>malloc()</I>,
<BR>
the Judy website,
<A href="http://judy.sourceforge.net">
http://judy.sourceforge.net</A>,
for more information and Application Notes.
</DL>
</BODY>
</HTML>
